package com.example.app.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.app.R;
import com.example.app.viewmodel.home.CouponList;

import java.util.List;

public class CouponListAdapter extends RecyclerView.Adapter<CouponListAdapter.ViewHolder> {
    private Context ctx;
    private List<CouponList> couponList;
    public CouponListAdapter(Context ctx, List<CouponList> couponList) {
        this.ctx = ctx;
        this.couponList = couponList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(this.ctx).inflate(R.layout.adapter_home_couponlist,null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.home_couponList_discount.setText("¥ " + couponList.get(position).getDiscount() + "  元");
        //holder.home_couponList_name.setText(couponList.get(position).getName());
        holder.home_couponList_desc.setText(couponList.get(position).getDesc() + "-无限制 有效期10天");
        //holder.home_couponList_tag.setText(couponList.get(position).getTag());
        //holder.home_couponList_day.setText("" + couponList.get(position).getDays());
    }

    @Override
    public int getItemCount() {
        int size = couponList.size();
        return size;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView home_couponList_discount;
        TextView home_couponList_name;
        TextView home_couponList_desc;
        TextView home_couponList_tag;
        TextView home_couponList_day;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            home_couponList_discount = itemView.findViewById(R.id.home_couponList_discount);
            home_couponList_name = itemView.findViewById(R.id.home_couponList_name);
            home_couponList_desc = itemView.findViewById(R.id.home_couponList_desc);
            home_couponList_tag = itemView.findViewById(R.id.home_couponList_tag);
            home_couponList_day = itemView.findViewById(R.id.home_couponList_day);
        }
    }
}
